﻿using System.Drawing;
using Microsoft.WowAddonStudio.FrameXml.Serialization;
using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Tests
{
	[TestFixture]
	public class LayoutFrameTest : FrameXmlControlTestBase
	{
		[Test]
		public void LayoutFrameSizeTest()
		{
			InitializeUi("Data/Simple/LayoutFrameSize.xml");

			var layoutFrameControl = (LayoutFrameControl) UiControl.Controls[0];

			Assert.AreEqual(new Size(50, 50), layoutFrameControl.Size);

			// Change the size of the underlying LayoutFrame
            layoutFrameControl.LayoutFrame.SizeDimension = new Dimension
			                                               	{
			                                               		AbsDimension = new AbsDimension {X = 25, Y = 25}
			                                               	};

			// Assert that the control's size has also changed
			Assert.AreEqual(new Size(25, 25), layoutFrameControl.Size);
		}

		[Test]
		public void TopLeftAnchorTest()
		{
			InitializeUi("Data/Simple/LayoutFrameTopLeftAnchor.xml");
			var layoutFrameControl = (LayoutFrameControl) UiControl.Controls[0];

			Assert.AreEqual(15, layoutFrameControl.Left);
			Assert.AreEqual(15, layoutFrameControl.Top);

			// Assert the explicit size that was given for the layout frame
			Assert.AreEqual(new Size(50, 50), layoutFrameControl.Size);
		}

		[Test]
		public void TopRightAnchorTest()
		{
			InitializeUi("Data/Simple/LayoutFrameTopRightAnchor.xml");
			var layoutFrameControl = (LayoutFrameControl) UiControl.Controls[0];

			Assert.AreEqual(UiControl.Width - 15, layoutFrameControl.Right);
			Assert.AreEqual(15, layoutFrameControl.Top);

			// Assert the explicit size that was given for the layout frame
			Assert.AreEqual(new Size(50, 50), layoutFrameControl.Size);
		}

		[Test]
		public void ImplicitSizeTest()
		{
			InitializeUi("Data/Simple/LayoutFrameImplicitSize.xml");
			var layoutFrameControl = (LayoutFrameControl) UiControl.Controls[0];

			// Assert TopLeft and BottomRight corners
			Assert.AreEqual(new Point(15, 15), layoutFrameControl.Location);
			Assert.AreEqual(new Point(UiControl.Width - 15, UiControl.Height - 15),
			                new Point(layoutFrameControl.Bottom, layoutFrameControl.Right));

			// Assert implicit size
			Assert.AreEqual(new Size(UiControl.Width - 30, UiControl.Height - 30), layoutFrameControl.Size);
		}
	}
}